import ImgPreview from "./index.vue";
import { createVNode, render } from "vue";

import type { Options, Props } from "./types";

let instance: any = null;

export function createImgPreview(options: Options) {
  const {
    imageList,
    show = true,
    index = 0,
    onSelect = null,
    onClose = null,
    zIndex = 500,
  } = options;

  const propsData: Partial<Props> = {};
  const container = document.createElement("div");
  propsData.imageList = imageList;
  propsData.show = show;
  propsData.index = index;
  propsData.zIndex = zIndex;
  propsData.onSelect = onSelect;
  propsData.onClose = onClose;

  document.body.appendChild(container);
  instance = createVNode(ImgPreview, propsData);
  render(instance, container);
}
